package com.smallkingson.ylib.view.utils;

import android.view.KeyEvent;
import java.util.Arrays;
import java.util.List;

/**
 * Created by yorun on 2018/5/10.
 */

public class YKeyDowns {
  //public static boolean handle(int keyCode, KeyEvent event,Object... objects) {
  //  if (objects==null ||objects.length==0) {
  //    return false;
  //  }
  //  return handle(keyCode,event,Arrays.asList(objects));
  //}
  public static boolean handle(int keyCode, KeyEvent event,Object[] objects) {
    if (objects==null ||objects.length==0) {
      return false;
    }
    return handle(keyCode,event,Arrays.asList(objects));
  }
  public static boolean handle(int keyCode, KeyEvent event,List objects) {
    for (Object object : objects) {
      if (object instanceof KeyListener) {
        KeyListener keyListener = (KeyListener) object;
        if (keyListener.onKeyDown(keyCode, event)) {
          return true;
        }
      }
    }
    return false;
  }
  public static interface KeyListener {
    boolean onKeyDown(int keyCode, KeyEvent event);
  }
}
